package com.zy.Conterller;

import com.zy.pojo.Pur;
import com.zy.service.PurService;
import com.zy.vo.ResultVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/sm/lin/")
public class PurCount {
    @Resource
    private PurService rootService ;
    @GetMapping("select")
    @RequiresPermissions("root:list")
    public ResultVo select(){

        return ResultVo.success(rootService.RootList());
    }
    @PostMapping("insert")
    @RequiresPermissions("root:add")
    public ResultVo insert(@RequestBody Pur pur){
        try{
            rootService.add(pur);
            return ResultVo.success("采购人添加成功");
        }catch (Exception e){
            return ResultVo.fail("采购人添加失败",e);
        }
    }
    @PostMapping("update")
    @RequiresPermissions("root:update")
    public ResultVo update(@RequestBody Pur pur){
        try{
           rootService.updateList(pur);
            return ResultVo.success("采购人修改成功");
        }catch (Exception e){
            return ResultVo.fail("采购人修改失败");
        }
    }
    @GetMapping("del/{id}")
    @RequiresPermissions("root:del")
    public ResultVo del(@PathVariable String id){
        try{
            rootService.del(Integer.parseInt(id));
            return ResultVo.success("采购人删除成功");
        }catch (Exception e){
            return ResultVo.fail("采购人删除失败");
        }
    }

}
